package common;

import java.util.Arrays;

public class ArrayStack {
    public int[] arr;
    public int r;

    public ArrayStack(int n) {
        this.arr = new int[n];
        this.r = 0;
    }

    public boolean isEmpty() {
        return r == 0;
    }

    // 入栈
    public void push(int e) {
        arr[r++] = e;
    }

    // 栈顶
    public int peek() {
        return r > 0 ? arr[r - 1] : -1;
    }

    // 出栈
    public int pop() {
        return arr[--r];
    }

    @Override
    public String toString() {
        return Arrays.toString(arr);
    }

}
